<!-- 免费项目管理 -->
<template>
  <div class="page-box h100 display-flex czbj" v-if="xczxctretre">
    <p class="title-label mb10">免费项目管理</p>
    <!-- sonRouter="yybureauFormationBJ" 为跳转新的页面编辑 -->
    <dxtable
      :dataJson="dataJson"
      :portUrl="portUrl"
      :formJson="formJson"
      :qx="qx"
      ref="databale"
    ></dxtable>
  </div>
</template>
<script lang="ts" setup>
import { apiUrl } from "@/util/config";
import dxtable from "../../components/util/dxtable.vue";
import sort from "../../components/util/sort.vue";
import { dxget, dxpost } from "../../util/index";
import { NButton, NImage, NTag } from "naive-ui";
import { h, ref, reactive } from "vue";
const databale = ref();
const xczxctretre = ref();
const mnxcfdfa = ref();
const mnxcfdfb = ref();
const portUrl = "jiacaihui/mfxm";
const initeer = () => {
  databale.value.initDataExpose();
};
let dataJson = [
  {
    title: "需求名称",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 24,
    key: "name",
    width: "",
    search: true,
    istable: true,
    required: false,
  },
  {
    title: "交付城市",
    type: "mapdz",
    icon: "dx-ditu",
    keyjw: "",
    span: 24,
    key: "jfcs",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "需求人数",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "xqrs",
    width: "100",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "职位性质",
    type: "select",
    icon: "dx-biaodanzujian-xialakuang",
    options: [],
    search: true,
    width: "100",
    key: "zwxz",
    render: (row) => {
      try {
        return mnxcfdfa.value.filter((a) => a.value == row.zwxz)[0].label;
      } catch (e) {
        return "--";
      }
    },
  },
  {
    title: "职能类别",
    type: "select",
    width: "100",
    icon: "dx-biaodanzujian-xialakuang",
    options: [],
    search: true,
    key: "znlb",
    render: (row) => {
      try {
        return mnxcfdfb.value.filter((a) => a.value == row.znlb)[0].label;
      } catch (e) {
        return "--";
      }
    },
  },
  {
    title: "审核",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "xqrs",
    width: "150",
    search: false,
    istable: true,
    required: false,
    render: (row) => {
      if (row.shzt == 1) {
        return h(
          NButton,
          {
            quaternary: true,
            type: "info",
            onClick: async () => {
              await dxpost(portUrl, { id: row.id, shzt: 2 }, "put");
              initeer();
            },
          },
          "点击通过审核"
        );
      } else {
        return h("span", { class: "ls" }, "已通过");
      }
    },
  },
  {
    title: "排序",
    width: 100,
    render: (row) => {
      row.sjk = "xtgx"; //数据库
      row.databaseName = "keyEnterprise"; //表名
      return h(sort, {
        row,
        onCallBack: () => {
          initeer();
        },
      });
    },
  },
  {
    title: "添加时间",
    key: "addTime",
    width: 150,
  },
];

const qx = {
  DeletePermissionID: "jiacaihuimfxmdel", //删除
  EditPermissionIdentifier: "jiacaihuimfxmbj", // 编辑
  NewPermissionIdentifier: "jiacaihuimfxmxz", // 新建
  ViewPermissionID: "jiacaihuimfxmck", // 查看
};

let formJson = reactive([
  {
    title: "需求名称",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 24,
    key: "name",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "交付城市",
    type: "mapdz",
    icon: "dx-ditu",
    keyjw: "",
    span: 24,
    key: "jfcs",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "需求人数",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "xqrs",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "职位性质",
    type: "select",
    icon: "dx-biaodanzujian-xialakuang",
    options: [],
    val: "1",
    span: 12,
    key: "zwxz",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "职能类别",
    type: "select",
    icon: "dx-biaodanzujian-xialakuang",
    options: [],
    val: "1",
    span: 12,
    key: "znlb",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "合作费用",
    type: "input",
    val: "",
    icon: "dx-shurukuang",
    span: 12,
    key: "hzfy",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
  {
    title: "项目描述",
    type: "textarea",
    val: "",
    icon: "dx-duohangwenben",
    span: 24,
    key: "xmms",
    width: "",
    search: false,
    istable: true,
    required: false,
  },
]);
const czFun = {
  fun: (row) => {
    return [
      h(
        NButton,
        {
          type: "info",
          quaternary: true,
          onClick: async (e) => {},
        },
        "复制代码"
      ),
    ];
  },
};

// 获取字典内容
const xtgxxmfl = async () => {
  const { data }: any = await dxget("dxgjAdmin/getzd", { name: "jchzwxz" });
  dataJson[3].options = [
    {
      label: "全部",
      value: "",
    },
    ...data,
  ];
  formJson[3].options = data;
  mnxcfdfa.value = data;
};

const xtjchznlbl = async () => {
  const { data }: any = await dxget("dxgjAdmin/getzd", { name: "jchznlb" });
  dataJson[4].options = [
    {
      label: "全部",
      value: "",
    },
    ...data,
  ];
  formJson[4].options = data;
  mnxcfdfb.value = data;
  console.log(data);
};
const kjxcdfs = async () => {
  await xtgxxmfl();
  await xtjchznlbl();
  xczxctretre.value = true;
};
kjxcdfs();
</script>
<style scoped></style>
